from rest_framework.viewsets import ModelViewSet
from goods.models import SPUSpecification
from goods.models import SPU
from meiduo_admin.utils import PageNum
from meiduo_admin.serializer.specs import SpecsSerialzier, SPUSerializer
from rest_framework.response import Response


class SpecsView(ModelViewSet):
    """
        规格规格的增删改查
    """
    # 指定查询集
    queryset = SPUSpecification.objects.all()
    # 指定序列化器
    serializer_class = SpecsSerialzier
    #
    pageination_class = PageNum

    def simple(self, request):
        """
        获取SPU商品规格所关联的
        :param request:
        :return:
        """
        spus = SPU.objects.all()
        ser = SPUSerializer(spus, many = True)

        return Response(ser.data)

    def destroy(self, request, *args, **kwargs):
        spec=self.get_object()
        spec.is_delete=True
        spec.save()